<?php
namespace app\index\controller;
use think\Controller;
use think\Log;
use Payment\Common\PayException;
use Payment\Client\Charge;
use Payment\Config;
use Payment\Client\Query;
use Payment\Client\Refund;


//use app\common\service\Payment;

class Index extends Controller
{
    public function index()
    {
        Log::info("3333333333333333333");
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
    }

	
	public function test() {
       //  $Payment=new Payment();
       //  pe($Payment->getPayList());
        date_default_timezone_set('Asia/Shanghai');
        $wxConfig= [
            'use_sandbox'       => false,// 是否使用 微信支付仿真测试系统

            'app_id'            => 'wx138f75e84b948401',  // 公众账号ID
            'mch_id'            => '1487979432',// 商户id
            'md5_key'           => 'dfsfsdfsdfsdfsdfsdfsdfasdfsdfsdf',// md5 秘钥
            'app_cert_pem'      => CACERT_PATH. 'wx_apiclient_cert.pem',
            'app_key_pem'       => CACERT_PATH . 'wx_apiclient_key.pem',
            'sign_type'         => 'MD5',// MD5  HMAC-SHA256
            'limit_pay'         => [
                //'no_credit',
            ],// 指定不能使用信用卡支付   不传入，则均可使用
            'fee_type'          => 'CNY',// 货币类型  当前仅支持该字段

            'notify_url'        => 'http://chongzhi.ruanduo.com/index/snotify/index/type/wx_charge',

            'redirect_url'      => 'http://chongzhi.ruanduo.com/index/index/return_url',// 如果是h5支付，可以设置该值，返回到指定页面

            'return_raw'        => true,// 在处理回调时，是否直接返回原始数据，默认为true
        ];




   /*    公众号
    $orderNo = time() . rand(1000, 9999);
// 订单信息
        $payData = [
            'body'    => 'test body',
            'subject'    => 'test subject',
            'order_no'    => $orderNo,
            'timeout_express' => time() + 600,// 表示必须 600s 内付款
            'amount'    => '0.01',// 微信沙箱模式，需要金额固定为3.01
            'return_param' => '123456',
            'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',// 客户地址
            'openid' => 'o6MuIwf4HUcB9CUmX8-Rat-xmIRQ',
            'product_id' => '101010',

            // 如果是服务商，请提供以下参数
            'sub_appid' => '',//微信分配的子商户公众账号ID
            'sub_mch_id' => '',// 微信支付分配的子商户号
            'sub_openid' => '',// 用户在子商户appid下的唯一标识
        ];

        try {
            $ret = Charge::run(Config::WX_CHANNEL_PUB, $wxConfig, $payData);
        } catch (PayException $e) {
            Log::error($e->errorMessage());
            echo $e->errorMessage();
            exit;
        }

        echo json_encode($ret, JSON_UNESCAPED_UNICODE);

        $this->assign('ret',$ret);
        return $this->fetch();*/


/*二维码
        $orderNo = time() . rand(1000, 9999);
    // 订单信息
        $payData = [
            'body'    => 'test body',
            'subject'    => 'test subject',
            'order_no'    => $orderNo,
            'timeout_express' => time() + 600,// 表示必须 600s 内付款
            'amount'    => '0.01',// 微信沙箱模式，需要金额固定为3.01
            'return_param' => '123',
            'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',// 客户地址
            'openid' => 'o6MuIwf4HUcB9CUmX8-Rat-xmIRQ',
            'product_id' => '123',

            // 如果是服务商，请提供以下参数
            'sub_appid' => '',//微信分配的子商户公众账号ID
            'sub_mch_id' => '',// 微信支付分配的子商户号
        ];

        try {
            $ret = Charge::run(Config::WX_CHANNEL_QR, $wxConfig, $payData);
        } catch (PayException $e) {
            echo $e->errorMessage();
            exit;
        }
        pe($ret);
        echo $ret;
*/
        $refundNo = time() . rand(1000, 9999);
        $data = [
            'out_trade_no' => '15048556252387',
            'total_fee' => '0.01',
            'refund_fee' => '0.01',
            'refund_no' => $refundNo,
            'refund_account' =>'REFUND_SOURCE_UNSETTLED_FUNDS',// REFUND_RECHARGE:可用余额退款  REFUND_UNSETTLED:未结算资金退款（默认）
        ];

        try {
            $ret = Refund::run(Config::WX_REFUND, $wxConfig, $data);
        } catch (PayException $e) {
            echo $e->errorMessage();
            exit;
        }

        echo json_encode($ret, JSON_UNESCAPED_UNICODE);
	}

    public function alipay()
    {


        $aliConfig= [
            'use_sandbox'               => true,// 是否使用沙盒模式

            'partner'                   => '2088102172166835',
            'app_id'                    => '2016082000291972',
            'sign_type'                 => 'RSA2',// RSA  RSA2

            // 可以填写文件路径，或者密钥字符串  当前字符串是 rsa2 的支付宝公钥(开放平台获取)
            'ali_public_key'            => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3jOsgmVIlk2lYm47AskKxmL3RAM92IYZHIpH3uja8elQyZpMQqX28Lk2kI4xrJrrVgBpnAVkHu4xAcz1iczqaDVXNKgcBY6GFn3bDh3gZTqe0C4QGx6L8S2PbVd9WkhkKvwcJMYr94GemhztlgE+RDYeQ0ZI23YgLcA/LvZw+pU9V7bnKjYRlYj+FbxCZSGPN3E9JNX2caAcQjJmxnPKolE7IS6HZAFB8/jKBF0f+eWE3FcAG1YVq6qFOWtCqt0sasNddIFLReZX9yqZCQp+79LKP2kmkDgMiBQof68UtZPG4QrMtZrKdVnS07XMMgrCJbj5uCLXafmrFh7xLw4gcQIDAQAB',

            // 可以填写文件路径，或者密钥字符串  我的沙箱模式，rsa与rsa2的私钥相同，为了方便测试
            'rsa_private_key'           => 'MIIEowIBAAKCAQEAzTo2yTfAVGynZUg/ew37ItbtPLPDHhHcn8irhz8edYpzkxto
KLUpy7qA27moHhEtsPLCOPnySvB1BHzbLwZs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ezIxG
p6x+Jaw+86a14N+zGntFx46lCF1lG8Bg1cx7iNon3qYo+yR3+YVuOBw/CXEJVep6
8l4cd5GVheSvw3Z/AYjcBTUCgYBasOyi5YLia3/SfDCTjwbCpQonKxCspEd51gGg
jKqw/FCFhXIAZPQmicQfjAqbfwxsP8IuNbBPkn//rp5/NOwxNa8bIk5IyTHO3sEd
8T4PNHSVdmRuJ6czvNH10lmKNTiWISmeNrAP4TPOs6W+w3y8DydnhzD/sYwnfM+e
cTnnoQKBgDsk3Yh8l1J1IFRrXFyKkThIH3u1OEXKqbznC13zuasVsa/YnSCb5Oqa
Nyuud+zySPu9dK/wzOBj/FyCPEE1gs7rNl6oORyBfcb2lLmi1OlTRKuRrssjzLUM
fZLB7ubWY5N/S+2NLivLnrqgSSNHFOogLiupAZJ1m5OUHQL84pxx',

            'limit_pay'                 => [
                //'balance',// 余额
                //'moneyFund',// 余额宝
                //'debitCardExpress',// 	借记卡快捷
                //'creditCard',//信用卡
                //'creditCardExpress',// 信用卡快捷
                //'creditCardCartoon',//信用卡卡通
                //'credit_group',// 信用支付类型（包含信用卡卡通、信用卡快捷、花呗、花呗分期）
            ],// 用户不可用指定渠道支付当有多个渠道时用“,”分隔

            // 与业务相关参数
            'notify_url'        => 'http://chongzhi.ruanduo.com/index/snotify/index/type/ali_charge',

            'return_url'      => 'http://chongzhi.ruanduo.com/index.php/index/index/return_url',// 如果是h5支付，可以设置该值，返回到指定页面

            'return_raw'                => true,// 在处理回调时，是否直接返回原始数据，默认为 true
        ];





        $refundNo = time() . rand(1000, 9999);
        $data = [
            'out_trade_no' => '15048483793581',
            'refund_fee' => '0.01',
            'reason' => '测试帐号退款',
            'refund_no' => $refundNo,
        ];

        try {
            $ret = Refund::run(Config::ALI_REFUND, $aliConfig, $data);
        } catch (PayException $e) {
            echo $e->errorMessage();
            exit;
        }

        echo json_encode($ret, JSON_UNESCAPED_UNICODE);
      // echo "<script> window.location.href='".$url."';</script>";
       // header('Location:' . $url);
    }

















    public function return_url(){
        pe(input());
    }
}



